/*
 * @Author: 张仁会 28396543@qq.com
 * @Date: 2022-09-11 17:01:09
 * @LastEditors: 张仁会 28396543@qq.com
 * @LastEditTime: 2022-09-11 17:38:18
 * @FilePath: \react-app\src\components\lazyLoading\lazyLoading.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useState, useEffect, useRef } from 'react'
const Lazy = (tar) => {
  let [flag, setFlag] = useState(false)
  const section = new IntersectionObserver((entries) => {
    if (entries[0].isIntersecting) {
      setFlag(true)
    } else {
      setFlag(false)
    }
  })
  useEffect(() => {
    tar && section.observe(tar)
  }, [tar])
  return flag
}
export default Lazy